package com.example.doer.reading;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.ab.view.pullview.AbPullToRefreshView;

import java.util.ArrayList;
import java.util.List;

import static android.os.SystemClock.sleep;
import static com.google.android.gms.internal.zzagz.runOnUiThread;


/**
 * A simple {@link Fragment} subclass.
 */
public class MessageFragment extends Fragment {

    private AbPullToRefreshView abPullToRefreshView=null;


    public MessageFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_message, container, false);

        ListView listView=(ListView) view.findViewById(R.id.message_list);
        List<Message>list=new ArrayList<Message>();

        list.add(new Message("Title","Contentssssssssssssssssxdxsxddxdxdxdxdxdx","2017-7-9",R.drawable.ic_launcher));
        list.add(new Message("Title","Content","2017-7-9",R.drawable.ic_launcher));
        list.add(new Message("Title","Content","2017-7-9",R.drawable.ic_launcher));
        list.add(new Message("Title","Content","2017-7-9",R.drawable.ic_launcher));

        MesListAdapter mesListAdapter=new MesListAdapter(getActivity(),list,R.layout.message_listview);
        listView.setAdapter(mesListAdapter);






        abPullToRefreshView=(AbPullToRefreshView)view.findViewById(R.id.mPullRefreshView);
        abPullToRefreshView.setOnHeaderRefreshListener(new AbPullToRefreshView.OnHeaderRefreshListener() {
            @Override
            public void onHeaderRefresh(final AbPullToRefreshView abPullToRefreshView) {
               refresh();
            }
        });
        abPullToRefreshView.setOnFooterLoadListener(new AbPullToRefreshView.OnFooterLoadListener() {
            @Override
            public void onFooterLoad(AbPullToRefreshView abPullToRefreshView) {

            }
        });

        return view;
    }
    public void refresh(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                sleep(2000);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        abPullToRefreshView.onHeaderRefreshFinish();
                    }
                });
            }
        }).start();
    }//end method of refresj

}//end class
